import { createStore, applyMiddleware } from 'redux'
import { combineReducers } from 'redux-immutable'
import thunk from 'redux-thunk'
import { composeWithDevTools } from '@redux-devtools/extension'

// 导入小的reducer
// import feed from '@/reducer/feed'
// const reducer = combineReducers({
//   feed:feed
// })

// 参数1：检索的路径  相对路径
// 参数2：是否递归检索
// 参数3：最终需要的文件扩展名 正则
const moduleFn = require.context('../reducer', false, /\.js$/i)
// 得到当前检索路径下面对应的所有的文件列表，进行迭代
const modules = moduleFn.keys().reduce((prev, curr) => {
  const key = curr.match(/\.\/(\w+)\.js$/i)[1]
  const value = moduleFn(curr).default
  prev[key] = value
  return prev
}, {})
const reducer = combineReducers(modules)

const store = createStore(reducer, composeWithDevTools(applyMiddleware(thunk)))

export default store
